import { defineStore } from "pinia";

export const layoutStore = defineStore('layout', {
    state: () => {
        return {
            isThemeDark: true,// 主题颜色 true黑色主题 false白色主题
            isCollapse: true,// 左侧栏 true收起 false展开
            routerViewLoading: false,
            LHeaderHMb: 0,// 头部高度 + 头部下边距
            LHeaderHMbBreadcrumbH: 0,// 头部高度 + 头部下边距 + 面包屑高度
            breadcrumb: [],// 面包屑
            fromRoutes: {},// 记录上个页面的地址name
        }
    },
    actions: {
        setBreadcrumb(value: ObjValueAny) {
            this.breadcrumb = value;
        },
        editBreadcrumbName(route: string, title: string) {
            for (let row of this.breadcrumb) {
                if (row.name === route) {
                    row.meta.name = title;
                }
            }
        }
    },
    persist: {
        enabled: true,// 开启持久化
        // 选择存储方式和内容
        strategies: [
            { storage: localStorage, paths: ['isThemeDark', 'isCollapse'] },
        ]
    }
});